package com.xiaomai.Action;

import javax.jms.Session;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.util.ValueStack;
import com.xiaomai.entity.UserEntity;
import com.xiaomai.server.LoginUser;
import com.xiaomai.server.LoginUserImpl;

public class UserAction {
	private UserEntity ue=new UserEntity();
	private UserEntity name=new UserEntity();
	//private ValueStack v=ActionContext.getContext().getValueStack();
		public UserEntity getName() {
		return name;
	}

	public void setName(UserEntity name) {
		this.name = name;
	}

		@Override
	public String toString() {
		return "UserAction [ue=" + ue + "]";
	}

		public UserEntity getUe() {
		return ue;
	}

	public void setUe(UserEntity ue) {
		this.ue = ue;
	}

		public String login(){
			ValueStack v=ActionContext.getContext().getValueStack();
			LoginUser u=new LoginUserImpl();
			System.out.println(ue);
			UserEntity login2 = u.login(ue);
			//System.out.println(user);
			if(login2.getPassword().equals(ue.getPassword())){
				v.setValue("#session.login", login2);
				return "login_success";
			}else{
				v.setValue("#request.error", "用户密码错误");
				return "error_success";
			}		
		}
		
		public String Registratio(){
			ValueStack v=ActionContext.getContext().getValueStack();
			LoginUser u=new LoginUserImpl();
			u.Registration(name);
			v.setValue("#session.name", name);
			System.out.println(name);
			return "Registratio_success";		
		}
		
		public String popup(){
			HttpSession session = ServletActionContext.getRequest().getSession();
			session.removeAttribute("login");
			return "popup_success";	
		}
	
}



